home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / OS / ZResUtils.h < prev    next >
Text File  |  1997-06-21  |  4KB  |  148 lines

  1. /*
  2.  *  File:       ZResUtils.h
  3.  *  Summary:    Resource manager utilities.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996-1997 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <2>     4/12/97    JDJ        Added GetResourceInfo. Added GetRefNum to TOpenResFile.
  12.  *         <1>     2/03/96    JDJ        Created
  13.  */
  14.  
  15. #pragma once
  16.  
  17. #include <Files.h>
  18.  
  19. #include <ZConstants.h>
  20. #include <ZTypes.h>
  21.  
  22.  
  23. //-----------------------------------
  24. //    Types
  25. //
  26. struct SResourceInfo {
  27.     ResType    type;
  28.     ResID    id;
  29.     string    name;
  30.     
  31.             SResourceInfo()                                            {type = '????'; id = 0;}
  32.             
  33.             SResourceInfo(ResType tp, ResID i, const string& nm)    {type = tp; id = i; name = nm;}
  34. };
  35.  
  36.  
  37. // ===================================================================================
  38. //    Reading
  39. // ===================================================================================
  40. void         ReadResource(ResType type, ResID id, void* buffer, ulong bytes);
  41.  
  42. void         Read1Resource(ResType type, ResID id, void* buffer, ulong bytes);
  43.  
  44.  
  45. void         ReadResource(ResType type, const string& name, void* buffer, ulong bytes);
  46.  
  47. void         Read1Resource(ResType type, const string& name, void* buffer, ulong bytes);
  48.  
  49.  
  50. // ===================================================================================
  51. //    Writing
  52. // ===================================================================================
  53. void         WriteResource(ResType type, ResID id, Handle data, bool purgeable = kNonPurgeable);
  54.             // Adds a new resource or overwrites an existing one.
  55.  
  56. void         WriteResource(ResType type, ResID id, const void* buffer, ulong bytes, bool purgeable = kNonPurgeable);
  57.  
  58.  
  59. void         WriteResource(ResType type, const string& name, Handle data, bool purgeable = kNonPurgeable);
  60.  
  61. void         WriteResource(ResType type, const string& name, const void* buffer, ulong bytes, bool purgeable = kNonPurgeable);
  62.  
  63.  
  64. // ===================================================================================
  65. //    Deleting
  66. // ===================================================================================
  67. void         Delete1Resource(ResType type);
  68.  
  69. void         DeleteResource(ResType type);
  70.  
  71. void         DeleteResource(ResType type, ResID id);
  72.  
  73. void         DeleteResource(ResType type, const string& name);
  74.  
  75.  
  76. // ===================================================================================
  77. //    Misc
  78. // ===================================================================================
  79. bool         Has1Resource(ResType type, ResID id);
  80.  
  81. bool         HasResource(ResType type, ResID id);
  82.  
  83. bool         Has1Resource(ResType type, const string& name);
  84.  
  85. bool         HasResource(ResType type, const string& name);
  86.  
  87. void         ChangeResourceName(Handle handle, const string& name);
  88.  
  89. Handle         ReleaseIfResource(Handle handle);
  90.  
  91. SResourceInfo GetResourceInfo(Handle hand);
  92.  
  93.     
  94. // ===================================================================================
  95. //    class TOpenResFile
  96. // ===================================================================================
  97. class TOpenResFile {
  98.  
  99. public:
  100.                         ~TOpenResFile();
  101.                             
  102.                         TOpenResFile(const FSSpec& spec, SignedByte Perm);
  103.                         // Perm can be fsRdPerm, fsWrPerm, fsRdWrPerm, fsRdWrShPerm.
  104.  
  105.             short         GetRefNum() const                {return mRefNum;}
  106.  
  107. private:
  108.     short    mRefNum;
  109. };
  110.  
  111.  
  112. // ===================================================================================
  113. //    class TSaveResFile
  114. // ===================================================================================
  115. class TSaveResFile {
  116.  
  117. public:
  118.                         ~TSaveResFile();
  119.                         // Restores the ResFile.
  120.                             
  121.                         TSaveResFile();
  122.                         // Saves the ResFile.
  123.  
  124.     explicit            TSaveResFile(short newResFile);
  125.                         // Will save the current ResFile and set newResFile as the new current ResFile.
  126.  
  127. private:
  128.     short    mSavedResFile;
  129. };
  130.  
  131.  
  132. // ===================================================================================
  133. //    class TNoResLoad
  134. // ===================================================================================
  135. class TNoResLoad {
  136.  
  137. public:
  138.                         ~TNoResLoad();
  139.         
  140.                         TNoResLoad();
  141.                         // Disables resource loading. Note that these may be nested.
  142.         
  143. private:
  144.     bool mDisabled;
  145. };
  146.  
  147.  
  148.